
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"


class publisher: public rclcpp::Node
{

public:
    publisher(std::string name):Node(name)
    {
        RCLCPP_INFO(this->get_logger(), "I am %s", name.c_str());
        publisher_ = this->create_publisher<std_msgs::msg::String>("command", 10);
        timer_ = this->create_wall_timer(std::chrono::seconds(1), std::bind(&publisher::timer_callback, this));
    }
    ~publisher()
    {

    }
private:
    void timer_callback()
    {
        std_msgs::msg::String msg;
        msg.data = "forward";
        RCLCPP_INFO(this->get_logger(), "Publish: %s", msg.data.c_str());
        publisher_->publish(msg);
    }

private:
    rclcpp::Publisher<std_msgs::msg::String>::SharedPtr publisher_;
    rclcpp::TimerBase::SharedPtr timer_;
};




int main(int argc, char **argv)
{
    rclcpp::init(argc, argv);

    auto node = std::make_shared<publisher>("publisher");
    RCLCPP_INFO(node->get_logger(), "publisher start");
    rclcpp::spin(node);
    rclcpp::shutdown();
    return 0;

}